package com.verisette.ncos.service.master.bizunit;

import java.util.List;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Required;

import org.corp.agi.common.exception.ProcessException;
import org.corp.agi.service.bean.ProcessContext;
import org.corp.agi.service.bizunit.CommonBusinessUnit;
import com.verisette.ncos.persistence.dao.UserGroupAuthorizationDAOImpl;
import com.verisette.ncos.persistence.domain.CustomMasterObjectAuthByUsg;
import com.verisette.ncos.persistence.domain.MasterObject;
import com.verisette.ncos.persistence.domain.MasterUserGroup;

import com.verisette.ncos.web.master.bean.UserGroupAuthorizationBean;

/**
 * {Description here}
 *
 * @author Thippawan Muangchu (Tip)
 * @since Mar 31, 2010 5:22:38 PM
 * @version 1.0.0
 * @see 
 */
public class FindUserGroupAuthorizationBU extends CommonBusinessUnit {
	private Logger logger = Logger.getLogger(FindUserGroupAuthorizationBU.class);

	//initial DAO
	private UserGroupAuthorizationDAOImpl userGroupAuthDAO;
	@Required
	@Autowired
	public void setUserGroupAuthorizationDAO(UserGroupAuthorizationDAOImpl userGroupAuthDAO) {
		this.userGroupAuthDAO = userGroupAuthDAO;
	}
	
	@Override
	public void execute(ProcessContext processContext) throws ProcessException {
		List<CustomMasterObjectAuthByUsg> listCustomMasterObjectAuthByUsg;
		List<MasterObject> listMaster;
		UserGroupAuthorizationBean bean;
		MasterUserGroup inputParam = (MasterUserGroup) processContext.getValueObject();
		int totalRows = userGroupAuthDAO.getAuthListByGroupTotal(inputParam);
		 if (totalRows > 0) {
			 bean = new UserGroupAuthorizationBean();
			 listCustomMasterObjectAuthByUsg = userGroupAuthDAO.getAuthListByGroup(inputParam, processContext.getPaging());
			 bean.setListCustomMasterObjectAuthByUsg(listCustomMasterObjectAuthByUsg);
			 bean.setIsObjListAll(false);
		 } else {
			 bean = new UserGroupAuthorizationBean();
			 listMaster = userGroupAuthDAO.getObjListAll( processContext.getPaging() );
			 bean.setListMasterObject(listMaster);
			 bean.setIsObjListAll(true);
		 }
		 
		 processContext.setValueObject(bean);
	}
}
